
#include "lcfg/LocalConfig.h"

#include <CarProperties.h>
#include <LocalConfig.h>

ANDROID_SINGLETON_STATIC_INSTANCE(vhal::LocalConfig)
namespace ecarx::transfer::lcfg {

LocalConfig& LocalConfig::getInstance() {
    static LocalConfig config;
    return config;
}

std::shared_ptr<ITransfer> LocalConfig::toTransfer() {
    return mTransfer;
}

LocalConfig::LocalConfig() : mTransfer(std::make_shared<LocalConfigTransfer>()) {}
LocalConfig::~LocalConfig() {}
template <typename T>
T LocalConfig::getInt(const LocalConfigProperty& key) {
    T def = std::any_cast<T>(key.getDefValue());
    return vhal::LocalConfig::getInstance().GetIntProperty(key.name(), def);
}
template <typename T>
T LocalConfig::getUInt(const LocalConfigProperty& key) {
    T def = std::any_cast<T>(key.getDefValue());
    return vhal::LocalConfig::getInstance().GetUintProperty(key.name(), def);
}
template int8_t LocalConfig::getInt(const LocalConfigProperty& key);
template int16_t LocalConfig::getInt(const LocalConfigProperty& key);
template int32_t LocalConfig::getInt(const LocalConfigProperty& key);
template int64_t LocalConfig::getInt(const LocalConfigProperty& key);

template uint8_t LocalConfig::getUInt(const LocalConfigProperty& key);
template uint16_t LocalConfig::getUInt(const LocalConfigProperty& key);
template uint32_t LocalConfig::getUInt(const LocalConfigProperty& key);
template uint64_t LocalConfig::getUInt(const LocalConfigProperty& key);

bool LocalConfig::getBool(const LocalConfigProperty& key) {
    auto def = std::any_cast<bool>(key.getDefValue());
    return vhal::LocalConfig::getInstance().GetBoolProperty(key.name(), def);
}
double LocalConfig::getDouble(const LocalConfigProperty& key) {
    auto def = std::any_cast<double>(key.getDefValue());
    return vhal::LocalConfig::getInstance().GetDoubleProperty(key.name(), def);
}
float LocalConfig::getFloat(const LocalConfigProperty& key) {
    auto def = std::any_cast<float>(key.getDefValue());
    return vhal::LocalConfig::getInstance().GetDoubleProperty(key.name(), def);
}
std::string LocalConfig::getString(const LocalConfigProperty& key) {
    auto def = std::any_cast<std::string>(key.getDefValue());
    return vhal::LocalConfig::getInstance().GetProperty(key.name(), def);
}
}  // namespace ecarx::transfer::lcfg
